﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Arizu.DAL;
using Arizu.Entity;

namespace Arizu.Repository
{
    public class Vouchers : BaseProvider
    {
        #region
        private static volatile Vouchers instance;
        private static object lockHelper = new object();

        private Vouchers()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static Vouchers CreateInstance()
        {
            if (instance == null)
            {
                lock (lockHelper)
                {
                    if (instance == null)
                    {
                        instance = new Vouchers();
                    }
                }
            }
            return instance;
        }
        #endregion

        /// <summary>
        /// 插入Vouchers信息
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public long InsertVouchers(VoucherEntity voucher)
        {
            string sql = "INSERT INTO Vouchers(Type,Value,UserId) VALUES (@Type,@Value,@UserId)";

            #region parameters
            SqlParameter parm_Type = new SqlParameter("@Type", voucher.Type);
            SqlParameter parm_Value = new SqlParameter("@Value", voucher.Value);
            SqlParameter parm_UserId = new SqlParameter("@UserId", voucher.UserId);

            SqlParameter[] parameters = { parm_Type, parm_Value, parm_UserId};
            #endregion

            try
            {
                DataSet ds = SqlHelper.ExecuteDataset(conn, CommandType.Text, sql, parameters);

                voucher.ID = long.Parse(ds.Tables[0].Rows[0][0].ToString());

            }
            catch (Exception ex)
            {

                throw new Exception(ex.Message);
            }
            return voucher.ID;
        }

        /// <summary>
        /// 根据User获取Vouchers信息
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public DataTable GetVouchers(long userId)
        {
            DataTable dt = new DataTable();
            string sql = "select * from Vouchers where UserId=" + userId;

            try
            {
                dt = SqlHelper.ExecuteDataset(conn, CommandType.Text, sql).Tables[0];
            }
            catch (Exception)
            {

                throw;
            }
            return dt;
        }
    }

    /// <summary>
    /// 租币类型
    /// </summary>
    public enum VirtualCurrencyType : int
    { 
        BRegist = 0, 
        BUploadImg = 1,
        BRegistFriand = 2,
        BFirstHire = 3,
        BReserveFriand = 4,
        BGiftAfterOrder = 5,
        BQuestionnaire = 6
    }
}
